<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>OOP PECL/rrd example</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="rrd.examples-procedural.html">Procedural PECL/rrd example</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="ref.rrd.html">RRD 函数</a></div>
 <div class="up"><a href="rrd.examples.html">范例</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="rrd.examples-oop" class="section">
  <h2 class="title">OOP PECL/rrd example</h2>
  <p class="para">
   <div class="example" id="example-4405">
    <p><strong>Example #1 OO usage of rrd</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$rrdFile&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">dirname</span><span style="color: #007700">(</span><span style="color: #0000BB">__FILE__</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">"/speed.rrd"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$outputPngFile&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">dirname</span><span style="color: #007700">(</span><span style="color: #0000BB">__FILE__</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">"/speed.png"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$creator&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">RRDCreator</span><span style="color: #007700">(</span><span style="color: #0000BB">$rrdFile</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"now&nbsp;-10d"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">500</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$creator</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addDataSource</span><span style="color: #007700">(</span><span style="color: #DD0000">"speed:COUNTER:600:U:U"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$creator</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addArchive</span><span style="color: #007700">(</span><span style="color: #DD0000">"AVERAGE:0.5:1:24"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$creator</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addArchive</span><span style="color: #007700">(</span><span style="color: #DD0000">"AVERAGE:0.5:6:10"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$creator</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">save</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$updater&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">RRDUpdater</span><span style="color: #007700">(</span><span style="color: #0000BB">$rrdFile</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$updater</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">update</span><span style="color: #007700">(array(</span><span style="color: #DD0000">"speed"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"12345"</span><span style="color: #007700">),&nbsp;</span><span style="color: #DD0000">"920804700"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$updater</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">update</span><span style="color: #007700">(array(</span><span style="color: #DD0000">"speed"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"12357"</span><span style="color: #007700">),&nbsp;</span><span style="color: #DD0000">"920805000"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$graphObj&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">RRDGraph</span><span style="color: #007700">(</span><span style="color: #0000BB">$outputPngFile</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$graphObj</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setOptions</span><span style="color: #007700">(<br />&nbsp;&nbsp;&nbsp;&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"--start"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"920804400"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"--end"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">920808000</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"--vertical-label"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"m/s"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"DEF:myspeed=</span><span style="color: #0000BB">$rrdFile</span><span style="color: #DD0000">:speed:AVERAGE"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"CDEF:realspeed=myspeed,1000,*"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"LINE2:realspeed#FF0000"<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">)<br />);<br /></span><span style="color: #0000BB">$graphObj</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">save</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="rrd.examples-procedural.html">Procedural PECL/rrd example</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="ref.rrd.html">RRD 函数</a></div>
 <div class="up"><a href="rrd.examples.html">范例</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
